package com.ay.controller;


import com.ay.entity.Student;
import com.ay.service.StudentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;



@RestController
public class StudentController {

    @Autowired
    StudentService studentService;


    @RequestMapping("/selectByNameAndAge")
    public List<Student> SelectByNameAndAge(@RequestParam String name, @RequestParam Integer age,@RequestParam Integer dangqianye) {
        PageHelper.startPage(dangqianye,2);
        List<Student> list = studentService.selectByNameAndAge(name, age);
        //用PageInfo对结果进行包装
        PageInfo pageInfo = new PageInfo(list);


        PageHelper.startPage(dangqianye,2);
 /*startPage后面的第一个查询语句会被按照pageSize分页(比如每页两个),并返还需要的当前页,这是封装好的方法,不必纠结,熟练使用就好*/
        return studentService.selectByNameAndAge(name,age,dangqianye);


    }
}
